import { createRouter, createWebHashHistory } from "vue-router";

const routes = [
  {
    path: "/",
    redirect: "/demo/home",
  },
  {
    path: "/demo",
    name: "demo",
    redirect: "/demo/home",
    children: [
      {
        path: "/demo/home",
        name: "demoHome",
        meta: {
          title: "Demo首页",
        },
        component: () => import("@/views/demo/Demo.vue"),
      },
      {
        path: "/demo/overlay1",
        name: "demoOverlay1",
        meta: {
          title: "Overlay1",
        },
        component: () => import("@/views/demo/Overlay1.vue"),
      },
      {
        path: "/demo/debug",
        name: "demoDebug",
        meta: {
          title: "Debug",
        },
        component: () => import("@/views/demo/DebugComponent.vue"),
      },
    ],
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
  scrollBehavior(to, from, savedPosition) {
    // if (savedPosition) {
    //   return savedPosition; // 恢复滚动位置
    // } else {
    //   return { top: 0 }; // 默认滚动到顶部
    // }
    return { top: 0 };
  },
});

export default router;
